/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entity.Slot;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

/**
 *
 * @author daz
 */
public class TimeDao extends SimpleJdbcDaoSupport {
    
    public List<Slot> getListSlot() {
        String query = "SELECT * FROM slots";
        return getSimpleJdbcTemplate().query(query, new SlotMapper());
    }
    
    public void insertNewSlot(Slot s) {
        String query = "INSERT INTO slots (des) VALUES('" + s.getDescription() + "')";
        getJdbcTemplate().execute(query);
    }
    
    private class SlotMapper implements ParameterizedRowMapper<Slot> {
        
        @Override
        public Slot mapRow(ResultSet rs, int rowNum) throws SQLException {
            Slot slot = new Slot();
            slot.setDescription(rs.getString("des"));
            slot.setId(rs.getInt("id"));
            return slot;
        }
    }
}
